package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Restaurant;
import com.ruoyi.system.mapper.RestaurantMapper;
import com.ruoyi.system.service.IRestaurantService;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 餐饮Service业务层处理
 *
 * @author 强盛酒店
 * @date 2023-03-08
 */
@Service
public class RestaurantServiceImpl implements IRestaurantService {
    @Autowired
    private RestaurantMapper restaurantMapper;

    /**
     * 查询餐饮
     *
     * @param id 餐饮主键
     * @return 餐饮
     */
    @Override
    public Restaurant selectRestaurantById(Long id) {
        return restaurantMapper.selectRestaurantById(id);
    }

    /**
     * 查询餐饮列表
     *
     * @param restaurant 餐饮
     * @return 餐饮
     */
    @Override
    public List<Restaurant> selectRestaurantList(Restaurant restaurant) {
        restaurant.setIsDeleted(NumberUtils.INTEGER_ZERO);
        return restaurantMapper.selectRestaurantList(restaurant);
    }

    /**
     * 新增餐饮
     *
     * @param restaurant 餐饮
     * @return 结果
     */
    @Override
    public int insertRestaurant(Restaurant restaurant) {
        restaurant.setCreateUser(SecurityUtils.getUserId());
        restaurant.setCreateTime(DateUtils.getNowDate());
        return restaurantMapper.insertRestaurant(restaurant);
    }

    /**
     * 修改餐饮
     *
     * @param restaurant 餐饮
     * @return 结果
     */
    @Override
    public int updateRestaurant(Restaurant restaurant) {
        restaurant.setUpdateUser(SecurityUtils.getUserId());
        restaurant.setUpdateTime(DateUtils.getNowDate());
        return restaurantMapper.updateRestaurant(restaurant);
    }

    /**
     * 批量删除餐饮
     *
     * @param ids 需要删除的餐饮主键
     * @return 结果
     */
    @Override
    public int deleteRestaurantByIds(Long[] ids) {
        return restaurantMapper.deleteRestaurantByIds(ids);
    }

    /**
     * 删除餐饮信息
     *
     * @param id 餐饮主键
     * @return 结果
     */
    @Override
    public int deleteRestaurantById(Long id) {
        return restaurantMapper.deleteRestaurantById(id);
    }

    @Override
    public int deleteRestaurantByIds2(Long[] ids) {
        for (Long id : ids) {
            Restaurant restaurant = restaurantMapper.selectRestaurantById(id);
            restaurant.setIsDeleted(NumberUtils.INTEGER_ONE);
            restaurantMapper.updateRestaurant(restaurant);
        }
        return 1;
    }
}
